<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 各类说明
 * Class Base
 * @author heyu
 */
class Explain extends MY_Controller {
    /**
     * @var AdmSettingModel
     */
    public $mSetting = null;

    /**
     * 初始化
     * User constructor.
     */
    public function __construct() {
        parent::__construct();
        $this->loadModel('AdmSettingModel', 'mSetting');
    }

    /**
     * 首页
     */
    public function index(){
        $list = $this->mSetting->getExplain('bonus_desc,coupon_desc,merchant_withdraw_desc,consumer_withdraw_desc,recharge_desc,
        to_store_desc,to_door_desc,reality_receive_explain,month_reality_recive_expain,integral_desc,agreement,merchant_agreement,
        merchant_discount_desc,distribution_fee_desc,postal_card_desc');

        $data = array(
            'list' => $list,
            'title' => '说明'
        );
        $this->view('config/explain', $data, 'validation,ueditor');
    }

    /**
     * 保存数据
     */
    public function save(){
        $vConf = array(
            array('bonus_desc', '红包', 'required'),
            array('coupon_desc', '代金劵', 'required'),
            array('merchant_withdraw_desc', '商家提现', 'required'),
            array('consumer_withdraw_desc', '消费者提现', 'required'),
            array('recharge_desc', '充值', 'required'),
            array('to_store_desc', '到店消费', 'required'),
            array('to_door_desc', '送货上门', 'required'),
            array('reality_receive_explain', '实际收款', 'required'),
            array('month_reality_recive_expain', '本月实际收款', 'required'),
            array('integral_desc', '积分说明', 'required'),
            array('agreement', '用户注册协议', 'required'),
            array('merchant_agreement', '商户注册协议', 'required'),
            array('merchant_discount_desc', '优惠说明', 'required'),
            array('distribution_fee_desc', '计费规则', 'required'),
            array('postal_card_desc', '包邮卡', 'required'),
        );
        $this->formDataValidation($vConf);
        $data = array(
            'bonus_desc' => trim(post('bonus_desc')),
            'coupon_desc' => trim(post('coupon_desc')),
            'merchant_withdraw_desc' => trim(post('merchant_withdraw_desc')),
            'consumer_withdraw_desc' => trim(post('consumer_withdraw_desc')),
            'recharge_desc' => trim(post('recharge_desc')),
            'to_store_desc' => trim(post('to_store_desc')),
            'to_door_desc' => trim(post('to_door_desc')),
            'reality_receive_explain' => trim(post('reality_receive_explain')),
            'month_reality_recive_expain' => trim(post('month_reality_recive_expain')),
            'integral_desc' => trim(post('integral_desc')),
            'agreement' => trim(post('agreement')),
            'merchant_agreement' => trim(post('merchant_agreement')),
            'merchant_discount_desc' => trim(post('merchant_discount_desc')),
            'distribution_fee_desc' => trim(post('distribution_fee_desc')),
            'postal_card_desc' => trim(post('postal_card_desc')),
        );
        if($this->mSetting->update($this->mSetting->tbExplain, $data)){
            $this->ajaxReturn(1, '保存成功', null, getUrl('config/explain'));
        }
        $this->ajaxReturn(0, '保存失败');
    }

}
